<?php    
    function getTree($data, $pid=0)
    {
        $tree = '';
        foreach($data as $k => $v)
        {
            if($v['parent_id'] == $pid)
            {        //父亲找到儿子
                $v['sub_menu'] = getTree($data, $v['id']);
                $tree[] = $v;
            }
        }
        return $tree;
    }